package com.zhdl.modules.demo.waringtest;

import cn.hutool.core.date.DateUtil;
import com.zhdl.modules.common.warn.entity.WarnRecords;
import com.zhdl.modules.common.warn.service.WarnRecordsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;

@Service
public class ProcessWarningService {
    @Resource
    WarnRecordsService warnRecordsService;
    public List<WarnRecords> currentWarnList = new ArrayList<>();

    public void addNewWarnService(WarnRecords warning){
        currentWarnList.add(warning);
    }

    public void addNewWarnService(String desc,int code){
        WarnRecords warning = new WarnRecords(code,desc);
        warning.setWarnStartTime(DateUtil.formatDateTime(new Date()));
        currentWarnList.add(warning);
    }

    public void resetAll(){
        for (WarnRecords myWarning : currentWarnList) {
            warnRecordsService.insert(new WarnRecords(myWarning.getWarnType(),myWarning.getWarnInfo()));
        }
        currentWarnList.clear();
    }


}
